Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom step support #1021

Merged
merged 29 commits into from
Aug 14, 2024
Merged

feat: add custom step support #1021

merged 29 commits into from
Aug 14, 2024

Conversation

WilliamBergamin
Copy link
Contributor

This PR includes all the changes from #986 aims to add support for custom functions in Bolt Python

Feedback

I'm looking for feedback on

  • Usability, is this what we envisioned the developer experience would be?
  • Does this aline with the Bolt-js experience?
  • Implementation, does this implementation align with bolt principles
  • Tests, is this missing tests that could be valuable for the feature

Testing

This gist was created to show how to test these new feature, use it with the following steps

  1. Create a new app
    a. Head to https://api.slack.com/apps/?new_app=1
    b. Click "From an app manifest"
    c. Select YAML and paste the above manifest.yml content
    d. Click create button
  2. Install the app into org/workspace
    a. Install the app anyways (when the workspace is in an Org, org-wide installation is required to publish functions)
    b. Grab the xoxb- token (Settings > Install App > Bot User OAuth Token)
    c. export SLACK_BOT_TOKEN=xoxb-...
  3. Set up Socket Mode
    a. Head to Settings > Basic Information > App-Level Tokens on the https://api.slack.com/apps page
    b. Generate a new token with connections:write scope
    c. export SLACK_APP_TOKEN=xapp-...
  4. Spin up the app
    a. Add app.py and async_app.py with the above source code
    b. Pull the latest PR branch of bolt python to your local
    c. Run scripts/build_pypi_package.sh this will generate a .whl in the dist/ folder
    d. (Optional) In your project set up a venv with python -m venv .venv and source .venv/bin/activate
    e. pip install global/path/to/bolt-python/dist/something.whl
    f. pip install aiohttp
    g python app.py or python async_app.py
  5. Add the custom step to a workflow
    a. Open the workflow builder
    b. Create a new workflow with a link trigger
    d. Seach "Hello" in the Steps view on the right side
    e. Add the step to the workflow (you can set any user ID as the input)
    f. Publish the workflow

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

* add listener

---------

Co-authored-by: Kazuhiro Sera <[email protected]>
Copy link

codecov bot commented Jan 25, 2024

Codecov Report

Attention: Patch coverage is 98.49246% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.00%. Comparing base (fbd6462) to head (cd82e9a).
Report is 1 commits behind head on main.

Files Patch % Lines
slack_bolt/request/internals.py 93.10% 2 Missing ⚠️
slack_bolt/context/base_context.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1021      +/-   ##
==========================================
+ Coverage   91.80%   92.00%   +0.19%     
==========================================
  Files         186      195       +9     
  Lines        6408     6605     +197     
==========================================
+ Hits         5883     6077     +194     
- Misses        525      528       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments

slack_bolt/app/app.py Outdated Show resolved Hide resolved
slack_bolt/app/app.py Outdated Show resolved Hide resolved
slack_bolt/app/async_app.py Outdated Show resolved Hide resolved
slack_bolt/context/complete/complete.py Outdated Show resolved Hide resolved
slack_bolt/context/fail/async_fail.py Outdated Show resolved Hide resolved
@WilliamBergamin WilliamBergamin marked this pull request as ready for review May 14, 2024 13:52
@sharvesh06
Copy link

@seratch @WilliamBergamin When will this PR be merged?

@WilliamBergamin
Copy link
Contributor Author

@sharvesh06 yess this PR will be merged soon!

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left some mostly comment-related nits and a few musings about edge cases. But, I ran through the new-app and existing-app tutorials and confirmed everything works as expected 🎉

slack_bolt/app/app.py Outdated Show resolved Hide resolved
def reverse_string(event: dict, client: WebClient, context: BoltContext):
try:
string_to_reverse = event["inputs"]["stringToReverse"]
client.functions_completeSuccess(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this example use the client directly, or the complete / fail shorthand parameter callbacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 💯 I think complete / fail shorthand parameter are better

This example it good to show how to hand roll completing a function 🤔 not sure where we could include it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just explaining what complete/fail do, and which underlying HTTP API methods they invoke, is sufficient. Link to the relevant methods and developers will figure the rest out.

slack_bolt/context/base_context.py Outdated Show resolved Hide resolved
slack_bolt/context/base_context.py Outdated Show resolved Hide resolved
slack_bolt/context/base_context.py Outdated Show resolved Hide resolved
slack_bolt/request/async_internals.py Show resolved Hide resolved
slack_bolt/request/async_internals.py Show resolved Hide resolved
@WilliamBergamin WilliamBergamin requested a review from filmaj August 13, 2024 15:49
@WilliamBergamin WilliamBergamin changed the title Add custom function support feat: add custom step support Aug 14, 2024
@WilliamBergamin WilliamBergamin merged commit 08be044 into main Aug 14, 2024
12 checks passed
@WilliamBergamin WilliamBergamin deleted the feat-functions branch August 14, 2024 19:35
@WilliamBergamin WilliamBergamin added this to the 1.20.0 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants